/**
 * Copyright (C), 2015-2020, XXX有限公司
 * FileName: AppHomeSaleAdapter
 * Author: Clark
 * Date: 2020/10/7 16:12
 * Description:
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
package sz.szsmk.citizencard.ui.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.vlayout.DelegateAdapter;
import com.alibaba.android.vlayout.LayoutHelper;
import com.alibaba.android.vlayout.layout.DefaultLayoutHelper;

import java.util.ArrayList;
import java.util.List;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.databinding.ApphomeModuleDayrecommendViewBinding;
import sz.szsmk.citizencard.model.network.bean.response.HomeWeathRes;
import sz.szsmk.citizencard.model.network.clarkbean.response.AdInfo;
import sz.szsmk.citizencard.model.network.clarkbean.response.AreaInfo;
import sz.szsmk.citizencard.ui.activity.ChargeActivity;
import sz.szsmk.citizencard.util.Constant;
import sz.szsmk.citizencard.util.JumpUtils;

/**
 * @ClassName: AppHomeSaleAdapter
 * @Description:
 * @Author: Clark
 * @Date: 2020/10/7 16:12
 */
public class AppHomeSaleAdapter extends DelegateAdapter.Adapter<AppHomeSaleAdapter.AppHomeSaleHolder> {
    private Context mContext;
    private LayoutHelper mGridLayoutHelper;
    private AreaInfo viewData;
    private ApphomeSaleGridAdapter apphomeSaleGridAdapter;
    private BaseInterface baseInterface;


    public interface BaseInterface {
        public void onClick(View view, String url, String syslabl, int need_header, String id, AdInfo bean);
    }

    public void setBaseInterface(BaseInterface baseInterface) {
        this.baseInterface = baseInterface;
    }

    public AppHomeSaleAdapter(FragmentActivity activity, DefaultLayoutHelper headHelper) {
        mContext = activity;
        mGridLayoutHelper = headHelper;

    }

    @Override
    public LayoutHelper onCreateLayoutHelper() {
        return mGridLayoutHelper;
    }

    @Override
    public AppHomeSaleHolder onCreateViewHolder(ViewGroup parent, int viewType) {
//        View view = LayoutInflater.from(mContext).inflate(R.layout.apphome_head_view_new, parent, false);
        return  AppHomeSaleHolder.creat(parent);
    }

    @Override
    public int getItemViewType(int position) {
        return R.layout.apphome_module_dayrecommend_view;
    }

    @Override
    public void onBindViewHolder(AppHomeSaleHolder holder, int position) {
//        holder.blurringView.setBlurredView();
       if(viewData!=null){
           holder.binding.dayrecommendTitle.setText(viewData.getResource_area_name());
           holder.binding.dayrecommenMore.setText(viewData.getResource_sub_title());
           holder.binding.dayrecommenMore.setOnClickListener(v -> {

               Bundle bundle = new Bundle();
               bundle.putString("url", viewData.getTitle_url());
               JumpUtils.jumptoNatvie(mContext, "webView", 0, bundle);

//               JumpUtils.jump(mContext,viewData.getTitle_url(),0);
           });
           loadItemData(position, holder.binding);
       }


    }
    private void loadItemData(int position, ApphomeModuleDayrecommendViewBinding binding) {
        if (viewData != null) {
            RecyclerView appSaleGrid = binding.saleList;
            GridLayoutManager manager = new GridLayoutManager(mContext, 2);
            apphomeSaleGridAdapter = new ApphomeSaleGridAdapter(mContext);
            apphomeSaleGridAdapter.setBaseInterface(new ApphomeSaleGridAdapter.BaseInterface() {
                @Override
                public void onClick(View view, String url, String syslabl, int need_header, String id, AdInfo bean) {
                    if (baseInterface!=null){
                        baseInterface.onClick(view,url,syslabl,need_header,id,bean);
                    }
                }
            });
            appSaleGrid.setLayoutManager(manager);
            appSaleGrid.setAdapter(apphomeSaleGridAdapter);
            apphomeSaleGridAdapter.setViewData(viewData.getAdInfoVoList());
            apphomeSaleGridAdapter.notifyDataSetChanged();
        }

    }
    @Override
    public int getItemCount() {
        return 1;
    }

    public void setViewData(AreaInfo viewData) {
        this.viewData = viewData;
    }

    public static class AppHomeSaleHolder extends RecyclerView.ViewHolder {
        private ApphomeModuleDayrecommendViewBinding binding;

        public static AppHomeSaleHolder creat(ViewGroup parent) {
            ApphomeModuleDayrecommendViewBinding binding =
                    ApphomeModuleDayrecommendViewBinding.inflate(LayoutInflater.from(parent.getContext()), parent, false);

            return new AppHomeSaleHolder(binding);
        }

        public AppHomeSaleHolder(ApphomeModuleDayrecommendViewBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }

    }

}
